package com.waypolice.manager.controller;

import com.waypolice.base.BaseController;
import com.waypolice.common.utils.*;
import com.waypolice.manager.service.VolAndItemService;
import com.waypolice.mapper.CmsJudItemMapper;
import com.waypolice.mapper.CmsJudVolumeMapper;
import com.waypolice.pojo.CmsJudItem;
import com.waypolice.pojo.CmsJudItemExample;
import com.waypolice.pojo.CmsJudVolume;
import com.waypolice.pojo.CmsJudVolumeExample;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @Description 卷件管理
 * @Author wangrang
 * @Date Created in 14:08 2019/3/12
 * @Modified By:
 */
@Controller
@Api(value = "卷件管理", description = "查询卷/件并进行操作")
@RequestMapping(value="/pcwindow")
public class VolAndItemAction extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(VolAndItemAction.class);

    @Autowired
    private VolAndItemService volAndItemService;

    @Autowired
    private CmsJudVolumeMapper cmsJudVolumeMapper;

    @Autowired
    private CmsJudItemMapper cmsJudItemMapper;

    /**
     * @author:wr
     * @description 跳转到卷件管理页面
     * @date:
     * @return
     */
    @ApiOperation(value = "跳转到卷件管理页面")
    @RequestMapping("/enter/volItemManagement")
    public String toVolItemManagement(){
        return "preArchive/selectVolAndItem";
    }

    @ApiOperation(value = "卷件管理卷数据查询")
    @RequestMapping(value = "/volume/volList", method = RequestMethod.GET)
    @ResponseBody
    public Object volList(HttpServletRequest request,
        @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
        @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
        @RequestParam(required = false, value = "sort") String sort,
        @RequestParam(required = false, value = "order") String order,
        String volTitle, String volNo,String volArchiveStatus) {

        boolean boo = StringUtils.isNotBlank(volTitle) || StringUtils.isNotBlank(volNo) || StringUtils.isNotBlank(volArchiveStatus);
        List<CmsJudVolume> cmsJudVolumes=null;
        if(boo){
            CmsJudVolumeExample cmsJudVolumeExample = new CmsJudVolumeExample();
            CmsJudVolumeExample.Criteria criteria = cmsJudVolumeExample.createCriteria();
            if(StringUtils.isNotBlank(volTitle)){
                criteria.andVolTitleLike("%"+volTitle+"%");}
            if(StringUtils.isNotBlank(volNo)){
                //数据库字段变更,将VolNo变为案卷号
                criteria.andVolNoEqualTo(volNo);
                //criteria.andVolCaseNumEqualTo(volCaseNum);
                }
            if(StringUtils.isNotBlank(volArchiveStatus)){
                criteria.andVolArchiveStatusEqualTo(Integer.valueOf(volArchiveStatus));
            }else {
                //新著录
                criteria.andVolArchiveStatusEqualTo(0);
            }
            if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
                sort= StringUtil.frontStrongToOracleString(sort);
                cmsJudVolumeExample.setOrderByClause(sort+" "+ order);
            }else {
                cmsJudVolumeExample.setOrderByClause("\"VOL_CREATE_DATE\" DESC");
            }
            cmsJudVolumes = volAndItemService.selectAllByQueryParms(cmsJudVolumeExample);
        }else {
            CmsJudVolumeExample cmsJudVolumeExample = new CmsJudVolumeExample();
            CmsJudVolumeExample.Criteria criteria = cmsJudVolumeExample.createCriteria();
            criteria.andVolArchiveStatusEqualTo(0); //初始只查询新著录的
            if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
                //cmsJudVolumeExample.setOrderByClause(sort + " " + order);
                sort= StringUtil.frontStrongToOracleString(sort);
                cmsJudVolumeExample.setOrderByClause(sort+" "+ order);
            }else {
                cmsJudVolumeExample.setOrderByClause("\"VOL_CREATE_DATE\" DESC");
            }
            cmsJudVolumes = volAndItemService.selectAllByQueryParms(cmsJudVolumeExample);
        }

        //最终的list集合,分页操作
        PageUtils<CmsJudVolume> pageUtils = new PageUtils<CmsJudVolume>();
        List<CmsJudVolume> cmsJudVolumesPage = pageUtils.pageList(cmsJudVolumes, offset, limit);

        Map<String, Object> result = new HashMap<>();
        result.put("rows",cmsJudVolumesPage);
        result.put("total",cmsJudVolumes.size());
        return result;
    }

    @ApiOperation(value = "卷件管理卷内件数据查询")
    @RequestMapping(value = "/item/itemList", method = RequestMethod.GET)
    @ResponseBody
    public String itemList(HttpServletRequest request,
                           @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                           @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                           String strParentID,String parentVolCarrier) {

        List<CmsJudItem> cmsJudItems = volAndItemService.selectAllByVolId(Long.valueOf(strParentID),2);
        cmsJudItems.stream().forEach(i -> i.setVolCarrier(parentVolCarrier));
        JSONArray jsonArray = JSONArray.fromObject(cmsJudItems);
        String string = jsonArray.toString();
        return string;
    }

    @ApiOperation(value = "删除卷和件的著录信息")
    @RequestMapping(value = "/volume/deleteVolumeAndItem", method = RequestMethod.POST)
    @ResponseBody
    public String deleteVolumeAndItem(HttpServletRequest request,String ids,String deleteTypeValue) {
        if(StringUtils.isNotBlank(ids)){
            String[] idArray = ids.split("-");
            int deleteFlag=0;
            for (String id : idArray) {
                int i = 0;
                try {
                    if("0".equals(deleteTypeValue)){
                        i = volAndItemService.deleteVolumeAndAllItem(Long.valueOf(id));
                    }else {
                        i = volAndItemService.deleteAllItemAndYuanWen(Long.valueOf(id));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if(i==0){
                    deleteFlag+=1;
                }
            }
            if(deleteFlag==0){
                return "success";
            }
        }
        return "请选中至少一行数据!";
    }

    @ApiOperation(value = "预归档提交")
    @RequestMapping(value = "/volumeAndItem/submitVolumeAndItem", method = RequestMethod.POST)
    @ResponseBody
    public String submitVolumeAndItem(HttpServletRequest request,String ids) {
        if(StringUtils.isNotBlank(ids)){
            String[] idArray = ids.split("-");
            ArrayList<String> obj = new ArrayList<>();
            for (String id : idArray) {
                CmsJudVolume cmsJudVolume2 = volAndItemService.selectCmsJudVolumeByVolId(Long.valueOf(id));
                //判断题名或者案卷号是否为空
                if(StringUtils.isBlank(cmsJudVolume2.getVolTitle()) ||
                        StringUtils.isBlank(cmsJudVolume2.getVolNo())){
                    obj.add(cmsJudVolume2.getVolNo());
                }else {
                    CmsJudVolume cmsJudVolume = new CmsJudVolume();
                    cmsJudVolume.setVolId(Long.valueOf(id));
                    cmsJudVolume.setVolArchiveStatus(1);//修改为待归档
                    //修改日期
                    cmsJudVolume.setVolEditDate(DateTimeUtil.getNow());
                    int i = volAndItemService.updateByPrimaryKeySelectiveNoCheck(cmsJudVolume);
                    if(i!=1){
                        CmsJudVolume cmsJudVolume1 = volAndItemService.selectCmsJudVolumeByVolId(Long.valueOf(id));
                        obj.add(cmsJudVolume1.getVolNo());
                    }
                }
            }
            if(obj.size() ==0){
                return "success";
            }else {
                String join = StringUtils.join(obj.toArray(), ",");
                // return join+"卷宗提交失败,请注意查看是否全部挂接原文!";
                return join+"案卷号提交失败!请检查题名/案卷号是否填写.";
            }
        }
        return "请选中一行数据!";
    }

    @ApiOperation(value = "获取原文地址")
    @RequestMapping(value = "/item/viewItemOriginal", method = RequestMethod.POST)
    @ResponseBody
    public String viewItemOriginal(HttpServletRequest request, HttpSession session, Long id) {

        String url = volAndItemService.selectByPojo(id);
        if(StringUtils.isNotBlank(url)){
            return url;
        }else {
            return "failure";
        }
    }

    @ApiOperation(value = "数据更新")
    @RequestMapping(value = "/volumeAndItem/refreshData", method = RequestMethod.POST)
    @ResponseBody
    public String refreshData(HttpServletRequest request) {
        CmsJudVolumeExample cmsJudVolumeExample = new CmsJudVolumeExample();
        CmsJudVolumeExample.Criteria criteria = cmsJudVolumeExample.createCriteria();
        ArrayList<Integer>  arcStatus= new ArrayList<>();
        arcStatus.add(0);
        arcStatus.add(1);
        arcStatus.add(3);
        arcStatus.add(4);
        arcStatus.add(5);
        criteria.andVolArchiveStatusIn(arcStatus);
        List<CmsJudVolume> cmsJudVolumes = cmsJudVolumeMapper.selectByExample(cmsJudVolumeExample);
        //生成档号
        String fileNumber = null;
        for (CmsJudVolume cmsJudVolume : cmsJudVolumes) {
            try {
                fileNumber = volAndItemService.getFileNumber(cmsJudVolume);
            } catch (Exception e) {
                e.printStackTrace();
            }
            int itemFlag=0;
            //统计件数
            CmsJudItemExample cmsJudItemExample = new CmsJudItemExample();
            CmsJudItemExample.Criteria criteria1 = cmsJudItemExample.createCriteria();
            criteria1.andItmeVolIdEqualTo(cmsJudVolume.getVolId());
            List<CmsJudItem> cmsJudItems = cmsJudItemMapper.selectByExample(cmsJudItemExample);
            cmsJudVolume.setVolItemNumber(String.valueOf(cmsJudItems.size()));
            //添加件号
            for (CmsJudItem cmsJudItem : cmsJudItems) {
                //String str = String.format("%04d", cmsJudItem.getItemPage());
                //将 件号=档号+页次 修改为 件号=档号+序号
                String str = String.format("%04d", cmsJudItem.getItemNum());
                String fileItemNumber = fileNumber + "-" + str;
                if(StringUtils.isNotBlank(cmsJudItem.getItemStr1()) && !fileItemNumber.trim().equals(cmsJudItem.getItemStr1().trim())){
                    cmsJudItem.setItemStr7(fileItemNumber);
                    itemFlag+=1;
                }else {
                    cmsJudItem.setItemStr1(fileItemNumber);
                }
                cmsJudItem.setItemStr11Date(DateTimeUtil.getNow());
                int i1 = cmsJudItemMapper.updateByPrimaryKeySelective(cmsJudItem);
            }
            if(cmsJudVolume.getVolArchiveStatus() == 0 || cmsJudVolume.getVolArchiveStatus() == 1 || cmsJudVolume.getVolArchiveStatus() == 2 || cmsJudVolume.getVolArchiveStatus() == 3 || cmsJudVolume.getVolArchiveStatus() == 4){
                cmsJudVolume.setVolCaseNum(fileNumber);
            }else if(cmsJudVolume.getVolArchiveStatus() == 5){
                cmsJudVolume.setVolStr4(fileNumber);
            }
            //确认卷内件是否都全部挂接完成
            int mount=0;
            for (CmsJudItem cmsJudItem : cmsJudItems) {
                if(StringUtils.isNotBlank(cmsJudItem.getItemStr2()) && "1".equals(cmsJudItem.getItemStr3())){
                    mount+=1;
                }
            }
            cmsJudVolume.setVolStr7(String.valueOf(mount));

            int i = cmsJudVolumeMapper.updateByPrimaryKey(cmsJudVolume);
        }
        return "success";
    }

    @ApiOperation(value = "上传Excel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    @ResponseBody
    public String importExcel(@RequestParam(value="excelFile",required=false)MultipartFile volExcelFile,
                              HttpServletRequest request,String volOrSinItem) {
        try {
            InputStream inputStream = volExcelFile.getInputStream();
            String fileName = volExcelFile.getOriginalFilename();
            if(!"xls".equals(fileName.split("\\.")[1]) && !"xlsx".equals(fileName.split("\\.")[1])){
                return "请选择正确的文件格式!";
            }
            long size = volExcelFile.getSize();
            ReadExcelUtils readExcelUtils = new ReadExcelUtils(inputStream,fileName);

            //form为0,获取Excel中第一张表格,目前第一张保存的为卷
            ArrayList<String> excelOneList = getExcelSheetOne(readExcelUtils);
            //form为1,获取Excel中第二张表格,目前第二张保存的件数据
            ArrayList<String> excelTwoList = getExcelSheetTwo(readExcelUtils);

            if(excelOneList.size()!=0 && excelTwoList.size()==0){
                String insertFailureByVol = StringUtils.join(excelOneList.toArray(), "、");
                return "上传成功，Excel中第"+insertFailureByVol+"行【卷】信息未导入，请核查。";
            }else if(excelOneList.size()==0 && excelTwoList.size()!=0){
                String insertFailureByItem = StringUtils.join(excelTwoList.toArray(), "、");
                return "上传成功，Excel中第"+insertFailureByItem+"行【件】信息未导入，请核查。";
            }else if(excelOneList.size()!=0 && excelTwoList.size()!=0){
                String insertFailureByVol2 = StringUtils.join(excelOneList.toArray(), "、");
                String insertFailureByItem2 = StringUtils.join(excelTwoList.toArray(), "、");
                return "上传成功，Excel中第"+insertFailureByVol2+"行【卷】信息未导入，第"+insertFailureByItem2+"行【件】信息未导入，请核查。";
            }
            return "success";
        } catch (Exception e) {
            LOGGER.error("导入数据IO异常:"+e);
            return "Erro：数据导入错误";
        }
    }

    /**
     * 传统导入获取Excel中第二个表
     * @param readExcelUtils
     * @return
     * @throws Exception
     */
    private ArrayList<String> getExcelSheetTwo(ReadExcelUtils readExcelUtils) throws Exception {
        List<Map<String, Object>> excelTwo = readExcelUtils.readExcelContent(1);
        ArrayList<String> excelTwoList = new ArrayList<>();
        int count=2;
        for (Map<String, Object> strMapItem : excelTwo) {
            if(strMapItem !=null){
                count += 1;
                CmsJudItem cmsJudItem = new CmsJudItem();
                cmsJudItem.setItemNum(strMapItem.get("itemNum")==null?null:Long.valueOf(strMapItem.get("itemNum").toString().split("\\.")[0]));
                cmsJudItem.setItemName(strMapItem.get("itemName")==null?null:strMapItem.get("itemName").toString());
                cmsJudItem.setItemTemporary(strMapItem.get("itemTemporary")==null?null:strMapItem.get("itemTemporary").toString());
                cmsJudItem.setItemSecret(strMapItem.get("itemSecret")==null?null:strMapItem.get("itemSecret").toString());
                cmsJudItem.setItemTitle(strMapItem.get("itemTitle")==null?null:strMapItem.get("itemTitle").toString());
                cmsJudItem.setItemRespons(strMapItem.get("itemRespons")==null?null:strMapItem.get("itemRespons").toString());
                cmsJudItem.setItemCreateTime(strMapItem.get("itemCreateTime")==null?null:strMapItem.get("itemCreateTime").toString());
                cmsJudItem.setItemPage(strMapItem.get("itemPage")==null?null:Long.valueOf(strMapItem.get("itemPage").toString().split("\\.")[0]));
                cmsJudItem.setItemStatus(strMapItem.get("itemStatus")==null?null:Long.valueOf(strMapItem.get("itemStatus").toString().split("\\.")[0]));
                cmsJudItem.setItemStr1(strMapItem.get("itemStr1")==null?null:strMapItem.get("itemStr1").toString());
                cmsJudItem.setItemStr2(strMapItem.get("itemStr2")==null?null:strMapItem.get("itemStr2").toString());
                cmsJudItem.setItemStr4(strMapItem.get("itemStr4")==null?null:strMapItem.get("itemStr4").toString());
                String itemStr4DateStr = strMapItem.get("itemStr4Date") == null ? null : strMapItem.get("itemStr4Date").toString();
                Date itemStr4Date =null;
                if(StringUtils.isNotBlank(itemStr4DateStr)){
                    itemStr4Date = DateTimeUtil.strToDateLong(itemStr4DateStr);
                }
                cmsJudItem.setItemStr4Date(itemStr4Date);

                String itemCreateDateStr = strMapItem.get("itemCreateDate") == null ? null : strMapItem.get("itemCreateDate").toString();
                Date itemCreateDate =null;
                if(StringUtils.isNotBlank(itemCreateDateStr)){
                    itemCreateDate = DateTimeUtil.strToDateLong(itemCreateDateStr);
                }
                cmsJudItem.setItemStr11Date(itemCreateDate);
                cmsJudItem.setItemStr5(strMapItem.get("itemStr5")==null?null:strMapItem.get("itemStr5").toString());
                cmsJudItem.setItemStr6(strMapItem.get("itemStr6")==null?null:strMapItem.get("itemStr6").toString());

                String sss = strMapItem.get("volCaseNum") == null ? null : strMapItem.get("volCaseNum").toString();
                if(StringUtils.isNotBlank(sss)){
                    //设置卷件对应关系
                    CmsJudVolumeExample cmsJudVolumeExample = new CmsJudVolumeExample();
                    CmsJudVolumeExample.Criteria criteria = cmsJudVolumeExample.createCriteria();
                    criteria.andVolCaseNumEqualTo(sss);
                    List<CmsJudVolume> cmsJudVolumes = cmsJudVolumeMapper.selectByExample(cmsJudVolumeExample);
                    if(cmsJudVolumes.size()==0){
                        //excelTwoList.add(strMapItem.get("ID")==null?"ID为空":strMapItem.get("ID").toString());
                        excelTwoList.add(String.valueOf(count));
                    }else {
                        Long volId = cmsJudVolumes.get(0).getVolId();
                        cmsJudItem.setItmeVolId(volId);
                        int iAsItem = cmsJudItemMapper.insertSelective(cmsJudItem);
                        if(iAsItem == 0){
                            //excelTwoList.add(strMapItem.get("ID").toString());
                            excelTwoList.add(String.valueOf(count));
                        }
                    }

                }else {
                    //excelTwoList.add(strMapItem.get("ID")==null?"ID为空":strMapItem.get("ID").toString());
                    excelTwoList.add(String.valueOf(count));
                }
            }
        }
        return excelTwoList;
    }

    /**
     * 传统导入获取Excel中第一个表
     * @param readExcelUtils
     * @return
     * @throws Exception
     */
    private ArrayList<String> getExcelSheetOne(ReadExcelUtils readExcelUtils) throws Exception {
        List<Map<String, Object>> excelOne = readExcelUtils.readExcelContent(0);
        ArrayList<String> excelOneList = new ArrayList<>();
        int flagVol=2;
        for (Map<String, Object> stringObjectMap : excelOne) {
            if(stringObjectMap!=null){
                flagVol+=1;
                CmsJudVolume cmsJudVolume = new CmsJudVolume();
                cmsJudVolume.setVolClass(stringObjectMap.get("volClass")==null?null:stringObjectMap.get("volClass").toString());
                cmsJudVolume.setVolStorageTime(stringObjectMap.get("volStorageTime")==null?null:stringObjectMap.get("volStorageTime").toString());
                cmsJudVolume.setVolNo(stringObjectMap.get("volNo")==null?null:stringObjectMap.get("volNo").toString());
                cmsJudVolume.setVolFian(stringObjectMap.get("volFian")==null?null:stringObjectMap.get("volFian").toString());
                cmsJudVolume.setVolTitle(stringObjectMap.get("volTitle")==null?null:stringObjectMap.get("volTitle").toString());
                cmsJudVolume.setVolArchiveYear(stringObjectMap.get("volArchiveYear")==null?null:stringObjectMap.get("volArchiveYear").toString());
                cmsJudVolume.setVolArchiveUnit(stringObjectMap.get("volArchiveUnit")==null?null:stringObjectMap.get("volArchiveUnit").toString());
                cmsJudVolume.setVolAuditLeader(stringObjectMap.get("volAuditLeader")==null?null:stringObjectMap.get("volAuditLeader").toString());
                cmsJudVolume.setVolAuditDate(stringObjectMap.get("volAuditDate")==null?null:stringObjectMap.get("volAuditDate").toString());
                cmsJudVolume.setVolSecret(stringObjectMap.get("volSecret")==null?null:stringObjectMap.get("volSecret").toString());
                cmsJudVolume.setVolInsideDate(stringObjectMap.get("volInsideDate")==null?null:stringObjectMap.get("volInsideDate").toString());
                cmsJudVolume.setVolTotal(stringObjectMap.get("volTotal")==null?null:stringObjectMap.get("volTotal").toString());
                cmsJudVolume.setVolCurrent(stringObjectMap.get("volCurrent")==null?null:stringObjectMap.get("volCurrent").toString());
                cmsJudVolume.setVolCaseNum(stringObjectMap.get("volCaseNum")==null?null:stringObjectMap.get("volCaseNum").toString());
                cmsJudVolume.setVolTotalPage(stringObjectMap.get("volTotalPage")==null?null:stringObjectMap.get("volTotalPage").toString());
                String sDate = stringObjectMap.get("volArchiveDate") == null ? null : stringObjectMap.get("volArchiveDate").toString();
                Date date =null;
                if(StringUtils.isNotBlank(sDate)){
                    date = DateTimeUtil.strToDateLong(sDate);
                }
                cmsJudVolume.setVolArchiveDate(date);

                cmsJudVolume.setVolCarrier(stringObjectMap.get("volCarrier")==null?null:stringObjectMap.get("volCarrier").toString());
                cmsJudVolume.setVolItemNumber(stringObjectMap.get("volItemNumber")==null?null:stringObjectMap.get("volItemNumber").toString());
                cmsJudVolume.setVolBoxNumber(stringObjectMap.get("volBoxNumber")==null?null:stringObjectMap.get("volBoxNumber").toString());
                cmsJudVolume.setVolStoragelocation(stringObjectMap.get("volStoragelocation")==null?null:stringObjectMap.get("volStoragelocation").toString());
                cmsJudVolume.setVolArchivePerson(stringObjectMap.get("volArchivePerson")==null?null:stringObjectMap.get("volArchivePerson").toString());
                cmsJudVolume.setVolStatus(stringObjectMap.get("volStatus")==null?null:Integer.valueOf(stringObjectMap.get("volStatus").toString()));
                cmsJudVolume.setVolPublicStatus(stringObjectMap.get("volPublicStatus")==null?null: Integer.valueOf(stringObjectMap.get("volPublicStatus").toString()));
                cmsJudVolume.setVolStr1(stringObjectMap.get("volStr1")==null?null:stringObjectMap.get("volStr1").toString());
                cmsJudVolume.setVolStr2(stringObjectMap.get("volStr2")==null?null:stringObjectMap.get("volStr2").toString());
                String createDateStr = stringObjectMap.get("volCreateDate") == null ? null : stringObjectMap.get("volCreateDate").toString();
                Date createDate =null;
                if(StringUtils.isNotBlank(createDateStr)){
                    createDate = DateTimeUtil.strToDateLong(createDateStr);
                }
                cmsJudVolume.setVolCreateDate(createDate);
                cmsJudVolume.setVolStr3(stringObjectMap.get("volStr3")==null?null:stringObjectMap.get("volStr3").toString());

                String volStr2DateStr = stringObjectMap.get("volStr2Date") == null ? null : stringObjectMap.get("volStr2Date").toString();
                Date volStr2Date =null;
                if(StringUtils.isNotBlank(volStr2DateStr)){
                    volStr2Date = DateTimeUtil.strToDateLong(volStr2DateStr);
                }
                cmsJudVolume.setVolStr2Date(volStr2Date);

                int iAsVol = cmsJudVolumeMapper.insertSelective(cmsJudVolume);
                if(iAsVol==0){
                    //excelOneList.add(stringObjectMap.get("ID").toString());
                    excelOneList.add(String.valueOf(flagVol));
                }
            }
        }
        return excelOneList;
    }

    /**
     * @author:zyp
     * @description 根据卷Id查询卷内容
     * @date: 2019/3/15 17:55
     * @return
     */
    @ApiOperation(value = "根据卷Id查询卷内容")
    @RequestMapping(value = "/volume/getVolById/{fileId}", method = RequestMethod.GET)
    @ResponseBody
    public Object getVolById(HttpServletRequest request,
                          @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                          @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                             @PathVariable("fileId") String fileId) {

        List<CmsJudVolume> cmsJudVolumes=new ArrayList<>();
        CmsJudVolume cmsJudVolume = volAndItemService.selectCmsJudVolumeByVolId(MathUtils.string2long(fileId));
        cmsJudVolumes.add(cmsJudVolume);
        Map<String, Object> result = new HashMap<>();
        result.put("rows",cmsJudVolumes);
        result.put("total",cmsJudVolumes.size());
        return result;
    }

    /**
     * @author:zyp
     * @description 根据件Id查询件内容
     * @date: 2019/3/15 18:06
     * @return
     */
    @ApiOperation(value = "根据件Id查询件内容")
    @RequestMapping(value = "/volume/getItemById/{fileId}", method = RequestMethod.GET)
    @ResponseBody
    public Object getItemById(HttpServletRequest request,
                          @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                          @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                             @PathVariable("fileId") String fileId,String strParentID) {

        List<CmsJudItem> cmsJudItems=new ArrayList<>();
        CmsJudItem cmsJudItem = volAndItemService.selectByItemId(MathUtils.string2long(fileId));
        cmsJudItems.add(cmsJudItem);
        Map<String, Object> result = new HashMap<>();
        result.put("rows",cmsJudItems);
        result.put("total",cmsJudItems.size());
        return result;
    }

    /**
     * @author:zyp
     * @description
     * @date: 2019/3/19 18:57
     * @return
     */
    @ApiOperation(value = "根据卷ID获取卷内件数据")
    @RequestMapping(value = "/item/findItemListByVolId", method = RequestMethod.GET)
    @ResponseBody
    public Object findItemListByVolId(HttpServletRequest request,
                           @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                           @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                           String strParentID) {
        List<CmsJudItem> cmsJudItems = volAndItemService.selectAllByVolId(Long.valueOf(strParentID),0);
        Map<String, Object> result = new HashMap<>();
        result.put("rows",cmsJudItems);
        result.put("total",cmsJudItems.size());
        return result;
    }

    /**
     * @author:zyp
     * @description 根据卷id 查看当前卷中是否存在其他状态的文件
     * @date: 2019/6/6 10:15
     * @return 
     */
    @ApiOperation(value = "根据卷id 查看当前卷中是否存在其他状态的文件")
    @RequestMapping(value = "/item/isOtherStatusByVoldId")
    @ResponseBody
    public Object isOtherStatusByVoldId(HttpServletRequest request,
                                      Long voId) {
        int count = volAndItemService.isOtherStatusByVoldId(voId);
        return count;
    }

}
